package day12.charstream;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/8/1
 */
public class CharStreamCase01 {
    /**
     * 保存键盘录入的数据
     *      将用户键盘录入的用户名和密码保存到本地实现永久化存储，
     *      要求用户名独占一行,密码独占-行。
     */
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();
        FileWriter fw = new FileWriter(
                "videoPractice\\src\\day12\\charstream\\CScase01.txt");
        fw.write(username);
        fw.write("\r\n");
        fw.write(password);
        fw.flush();
        fw.close();
//        method1(username, password, fw);
//        method2(username, password, fw);
    }

    private static void method2(String username, String password, FileWriter fw) throws IOException {
        String[] s = {"username:", username, "\r\n", "password:", password};
        for (String s1 : s) {
            fw.write(s1);
        }
    }

    private static void method1(String username, String password, FileWriter fw) throws IOException {
        fw.write("username:\r\n");
        fw.write(username);
        fw.write("\r\n");
        fw.write("password:\r\n");
        fw.write(password);
    }
}
